﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

public class IPAddressParse
{
    public static bool TryParse(string ipOrDomain, out IPAddress ipAddress)
    {
        ipAddress = null;

        if (string.IsNullOrEmpty(ipOrDomain))
        {
            return false;
        }

        bool isIP = IPAddress.TryParse(ipOrDomain, out ipAddress);
        if (isIP)
        {
            return true;
        }

        IPAddress[] ipAddressArray = Dns.GetHostAddresses(ipOrDomain);
        ipAddress = ipAddressArray[0];
        return true;
    }
}
